package response

import (
	"gin-chat/pkg"
	"github.com/gin-gonic/gin"
)

type Gin struct {
	C *gin.Context
}

//统一返回的结构体
type Response struct {
	Msg  string      `json:"msg"`
	Code int         `json:"code"`
	Data interface{} `json:"data"`
}

//封装统一格式返回数据
func (c *Gin) Response(httpCode int, code int, data interface{}) {
	c.C.JSON(httpCode, &Response{
		Code: code,
		Msg:  pkg.Code2msg(code),
		Data: data,
	})
	c.C.Abort()
}
